<?php
namespace app\process;

use Workerman\Crontab\Crontab;

class Task
{
    public function onWorkerStart()
    {
        $taskDir = __DIR__ . '/../crontab/';
        foreach (glob($taskDir . '*.php') as $file) {
            require_once $file;
            $class = 'app\\crontab\\' . basename($file, '.php');
            if (class_exists($class) && property_exists($class, 'rule') && method_exists($class, 'run')) {
                $rule = $class::$rule;
                new Crontab($rule, [$class, 'run']);
            }
        }
    }
}